package com.xiaoma.tpo.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.ClsCourse;
import com.xiaoma.tpo.dto.ClsCourseGateVo;

@Repository
public class ClsCourseDao extends BaseDaoImpl<ClsCourse> {

    private static final Logger LOG = LoggerFactory.getLogger(ClsCourseDao.class);
    @SuppressWarnings("unchecked")
    public List<ClsCourseGateVo> findCoursesByClassId(int classId) {
        String sql = "select a.*,b.id gate_id, b.name gate_name, b.desc gate_desc, b.audio_zip gate_audio_zip, b.type gate_type , b.seq_num gate_seq_num " +
                        "from cls_course a left join cls_gate b on a.id = b.cls_course_id where a.cls_class_id = ? order by a.id, b.seq_num asc";
        LOG.info("SQL:{} classId:{}", sql, classId);
        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(ClsCourseGateVo.class, getNameHandler()), classId);
        return (List<ClsCourseGateVo>)result;
    }


}
